package  
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	import ginger.ui.simple.SimpleBrightnessButton;
	import UILib.RulerBmpdata;
	import UILib.SilderBmpdata;
	/**
	 * ...
	 * @author Ning
	 */
	public class Ruler extends Sprite
	{
		private var _rulerBmp:Bitmap;
		private var _sliderBtn:SimpleBrightnessButton;
		//滑块区域
		private var _sliderRect:Rectangle;
		private var _wall:Wall;
		public function Ruler(wall:Wall) 
		{
			_wall = wall;
			_sliderRect = new Rectangle(0, -20, 526,0);
			
			_rulerBmp = new Bitmap(new RulerBmpdata());
			addChild(_rulerBmp);
			
			var btnBmp:Bitmap = new Bitmap(new SilderBmpdata);
			btnBmp.x = -28;
			_sliderBtn = new SimpleBrightnessButton(btnBmp,100);
			addChild(_sliderBtn);
			_sliderBtn.y = -20;
			_sliderBtn.x = 477 / 2;
			
			_sliderBtn.addEventListener(MouseEvent.MOUSE_DOWN, scrollSliderMouseDownHandler);
			Global.STAGE.addEventListener(MouseEvent.MOUSE_UP, scrollSliderMouseUpHandler);
			addEventListener(Event.ENTER_FRAME, render);
		}
		/**
		 * 滑块按下操作
		 * @param	evt
		 */
		private function scrollSliderMouseDownHandler(evt:MouseEvent):void
		{
			_sliderBtn.startDrag(true, _sliderRect);
		}
		
		/**
		 * 滑块弹起操作
		 * @param	evt
		 */
		private function scrollSliderMouseUpHandler(evt:MouseEvent):void
		{
			
			_sliderBtn.stopDrag();
		}
		
		/**
		 * 渲染
		 * @param	evt
		 */
		private function render(evt:Event=null):void
		{
			var per:Number = _sliderBtn.x / 526
			_wall.targetRotationPer = per;
		}
		
		public function moveSlider(value:Number):void
		{
			var x:Number = _sliderBtn.x + value;
			if (x < 0)
			    x = 0
			else if (x > 526)
			    x = 526;
			_sliderBtn.x = x;
		}	
	}

}